<?php 		
	class DataProvider{		
		var $m_hostname ='localhost';
		var $m_userName ='root';
		var $m_password='';
		var $m_db ='english';
		var $m_dbCon = null;		
		public static function ExecuteQuery($mysql){
			$connection = mysql_connect($m_hostname,$m_userName,$m_password) or
			die ("couldn't connect to localhost");
			mysql_select_db($m_db,$connection);
			mysql_query("set names 'utf8'");
			$result = mysql_query($mysql,$connection);
			mysql_close($connection);
			return $result;
		}
		public static function ExecuteQueryJson($mysql){
			$connection = mysql_connect("localhost","root","",'json') or
			die ("couldn't connect to localhost");
			mysql_select_db("english",$connection);
			mysql_query("set names 'utf8'");
			$result = mysql_query($mysql,$connection);
			mysql_close($connection);
			return $result;
		}
                
		public static function ExecuteQueryParamter($procName,$names,$values,$types){
			$mysqli = new mysqli('localhost', 'root','', 'english');
                        $stmt = $mysqli->prepare($procName);
                        $sp = new Statement_Parameter(); 
                        for($i =0;$i<count($values);$i++){
                            $name = $names[$i];
                            $type = $types[$i];
                            $value = $values[$i];
                            $sp->Add_Parameter($name, $type,$value);
                            echo "<br/> i = " .$i ." name = " .$name . " value = " .$value;
                        }
                        
                        $sp->Bind_Params($stmt);
                        $stmt->execute();
                        //$stml->close();
		}
	}
        
        class Statement_Parameter_Type {
            public static $STATEMENT_TYPE_INTEGER = 'i';//kieu du lieu kieu so
            public static $STATEMENT_TYPE_DOUBLE = 'd';
            public static $STATEMENT_TYPE_STRING = 's';
            public static $STATEMENT_TYPE_BLOB = 'b';
        }
        
        class Statement_Parameter {

            private $_array = array();

            public function __constructor() {

            }

            public function Add_Parameter($name, $type, $value = NULL) {
                $this->_array[$name] = array("type" => $type, "value" => $value);
                //name tuong ung voi tham so duoi ham proc
            }

            public function Get_Type_String() {
                $types = "";
                foreach ($this->_array as $name => $la) {
                    $types .= $la['type'];
                }
                return $types;
            }

            public function Set_Parameter($name, $value) {
                if (isset($this->_array[$name])) {
                    $this->_array[$name]["value"] = $value;
                    return true;
                }
                return false;
            }

            public function Bind_Params(&$stmt) {
                $ar = Array();
                $ar[] = $this->Get_Type_String();
                foreach ($this->_array as $name => $la)
                    $ar[] = &$this->_array[$name]['value'];
                echo json_encode($ar);
                return call_user_func_array(array($stmt, 'bind_param'), $ar);
            }
        }
?>